//
//  YTDelayCell.m
//  YUNT
//
//  Created by 梁炜东 on 2017/11/21.
//  Copyright © 2017年 梁炜东. All rights reserved.
//

#import "YTDelayCell.h"
#import "ZYXRuler.h"

#define rulerWidth 260
#define rulerHeight 50

@interface YTDelayCell()<ZYXRulerDelegate>
@property(nonatomic, strong)ZYXRuler *ruler;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UIImageView *titleImage;
@property(nonatomic, strong)UISwitch *switchBtn;
@property(nonatomic, strong)UILabel *subLabel;
@property(nonatomic, strong)UIButton *titleBtn;
@end

@implementation YTDelayCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self addSubview:self.ruler];
        [self addSubview:self.titleLabel];
        [self addSubview:self.subLabel];
        [self addSubview:self.titleImage];
        [self addSubview:self.switchBtn];
        [self addSubview:self.titleBtn];
        [self p_makeConstraints];
    }
    return self;
}
-(void)p_makeConstraints
{
//    [_ruler mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.leading.bottom.trailing.equalTo(self);
//    }];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.trailing.equalTo(self);
        make.leading.equalTo(self).offset(10);
    }];
    [_subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.bottom.equalTo(self);
        make.trailing.equalTo(self).offset(-10);
    }];
    [_switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(_subLabel);
        make.centerY.equalTo(self);
        make.width.mas_equalTo(51);
        make.height.mas_equalTo(31);
    }];
    [_titleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.leading.equalTo(self).offset(10);
        make.width.mas_equalTo(15);
    }];
    [_titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.bottom.trailing.equalTo(self);
    }];
}
-(ZYXRuler *)ruler
{
    if (!_ruler)
    {
        _ruler = [[ZYXRuler alloc] initWithFrame:CGRectMake(0, 0, rulerWidth-30, rulerHeight)];
        _ruler.rulerDeletate = self;
        _ruler.layer.frame = CGRectMake(0, 0, rulerWidth-30, rulerHeight);
    }
    return _ruler;
}
-(UILabel *)titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = YTColor(160, 160, 160);
        _titleLabel.font = [UIFont systemFontOfSize:17];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLabel;
}
-(UILabel *)subLabel
{
    if (!_subLabel)
    {
        _subLabel = [[UILabel alloc] init];
        _subLabel.textColor = [UIColor whiteColor];
        _subLabel.font = [UIFont systemFontOfSize:21];
        _subLabel.textAlignment = NSTextAlignmentRight;
    }
    return _subLabel;
}
-(UIImageView *)titleImage
{
    if (!_titleImage)
    {
        _titleImage = [[UIImageView alloc] init];
        _titleImage.backgroundColor = [UIColor clearColor];
        _titleImage.contentMode = UIViewContentModeScaleAspectFit;
        _titleImage.image = IMAGE(@"68");
    }
    return _titleImage;
}
-(UISwitch *)switchBtn
{
    if (!_switchBtn)
    {
        _switchBtn = [[UISwitch alloc] init];
        [_switchBtn addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _switchBtn;
}
-(UIButton *)titleBtn
{
    if (!_titleBtn)
    {
        _titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _titleBtn.backgroundColor = [UIColor clearColor];
        [_titleBtn setTitle:Language(@"开始") forState:UIControlStateNormal];
        [_titleBtn setTitleColor:YTColor(92, 204, 225) forState:UIControlStateNormal];
        _titleBtn.titleLabel.font = [UIFont systemFontOfSize:19];
        _titleBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        _titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [_titleBtn addTarget:self action:@selector(titleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _titleBtn;
}
-(void)configObject
{
    _titleBtn.hidden = YES;
    if (_indexPath.section == 0)
    {
        _titleLabel.hidden = YES;
        _subLabel.hidden = NO;
        _titleImage.hidden = YES;
        _switchBtn.hidden = YES;
        _subLabel.font = [UIFont systemFontOfSize:15];
        _ruler.rulerScrollView.arrayText = @[@"0.5", @"1", @"2", @"3", @"4", @"5",@"7", @"8", @"9", @"10", @"11"];
        [_ruler showRulerScrollViewWithCount:0 average:[NSNumber numberWithFloat:0.1] currentValue:publicModel.delaySpace smallMode:YES];
        _subLabel.text = @"s";
        self.backgroundColor = YTColor(35, 35, 35);
    }else
    {
        if (_indexPath.row == 0)
        {
            _titleLabel.hidden = YES;
            _subLabel.hidden = NO;
            _titleImage.hidden = YES;
            _switchBtn.hidden = YES;
            _subLabel.font = [UIFont systemFontOfSize:15];
            _ruler.rulerScrollView.arrayText = @[@"1", @"2", @"3", @"4", @"5", @"6",@"7", @"8", @"9", @"10", @"30", @"60"];;
            [_ruler showRulerScrollViewWithCount:0 average:[NSNumber numberWithFloat:0.1] currentValue:publicModel.delayContinue smallMode:YES];
            _subLabel.text = @"min";
            self.backgroundColor = YTColor(35, 35, 35);
        }else if (_indexPath.row == 1)
        {
            _titleLabel.hidden = NO;
            _subLabel.hidden = NO;
            _titleImage.hidden = YES;
            _switchBtn.hidden = YES;
            _ruler.hidden = YES;
            _subLabel.font = [UIFont systemFontOfSize:21];
            _titleLabel.text = Language(@"生成视频");
            //            _subLabel.text = 通过间隔和持续算出来
            _subLabel.text = @"00:00:06";
            self.backgroundColor = YTColor(57, 57, 57);
            
            UIView *line = [[UIView alloc] init];
            line.backgroundColor = YTColorAlpha(210, 210, 210, 0.3);
            [self addSubview:line];
            [line mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.leading.trailing.equalTo(self);
                make.bottom.equalTo(self).offset(0.5);
                make.height.mas_equalTo(1);
            }];
        }else if (_indexPath.row == 2)
        {
            _titleLabel.hidden = NO;
            _subLabel.hidden = YES;
            _titleImage.hidden = NO;
            _switchBtn.hidden = NO;
            _ruler.hidden = YES;
            _titleLabel.text = Language(@"三脚架模式");
            self.backgroundColor = YTColor(57, 57, 57);
        }else if (_indexPath.row == 3)
        {
            _titleBtn.hidden = NO;
            _titleLabel.hidden = YES;
            _subLabel.hidden = YES;
            _titleImage.hidden = YES;
            _switchBtn.hidden = YES;
            _ruler.hidden = YES;
            self.backgroundColor = YTColor(35, 35, 35);
        }
    }
    if (_indexPath.section == 1 && _indexPath.row == 2)
    {
        [_titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self).offset(10+15+10);
        }];
    }else
    {
        [_titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self).offset(10);
        }];
    }
}
#pragma mark action
-(void)switchAction:(UISwitch *)sender
{
    
}
-(void)titleBtnAction:(UIButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(delegateStartBtnAction:)])
    {
        [self.delegate delegateStartBtnAction:sender];
    }
}
#pragma mark ZYXRulerDelegate
//当前所在位置值
- (void)delegateRulerCurrentValue:(NSString *)key
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(delegateRulerIndexPath:Value:)])
    {
        [self.delegate delegateRulerIndexPath:_indexPath Value:key];
    }
}
@end
